#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMap>
#include "dep/Qss/Qss.h"

class KvPickOp;

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE


class MainWindow : public QssMainWindow
{
    Q_OBJECT

    using super_ = QssMainWindow;

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

protected:

    void closeEvent(QCloseEvent *e) override;

private slots:

    void on_sdSimilarity_valueChanged(int value);

    void on_btnCopy_clicked();

    void on_btnCut_clicked();

    void on_btnRemove_clicked();

    void on_btnStart_clicked();

    void on_toolbutton_toggled(bool checked);

    void on_btnAddAllDrivers_clicked();

    void on_btnAddUserHome_clicked();

    void on_checkedFiles_changed(int checkedFiles, qint64 totalSize);

    // 新增文件统计数量
    void updateTotalFiles(int moreFiles);

private:

    // 根据当前选中的pick卡片，创建并返回响应的pick操作对象
    KvPickOp* makePickOp_();

    void showStatusMessage_(const QString& title, const QString& body, bool updateUi);

    enum KePickState { k_pick_ready, k_pick_preparing, k_pick_running, k_pick_finished };
    KePickState pickState_() const { return state_; }
    bool isBusy_() const { return state_ == k_pick_preparing || state_ == k_pick_running; }

    // 从当前状态@state_转换到目标状态@state
    // 该函数统一处理状态同步问题，其他涉及状态转换的函数都应调用该函数
    void switchState_(KePickState state);

    void startPreparing_();
    void startPicking_();
    void stopPreparing_();
    void stopPicking_();

    void updateUi_(KePickState state);

    // 更新配置区域（位于“开找”按钮左侧）
    void updateConfig_(KePickState state);

    void execSelectOp_(int type);

    QString formatResultStats_() const;

    QString formatMsgTitle_() const;

private:
    Ui::MainWindow *ui;

    int filesTotal_{0}; // 须扫描的文件总量
    int filesPicked_{0}; // 已扫描的文件数量
    int filesRead_{0};
    int filesDone_{0};
    int filesFailed_{0};

    KePickState state_{ k_pick_ready };
};
#endif // MAINWINDOW_H
